import numpy as np
import h5py
import math


def add(a, b):
    return a + b


def exp(x):
    return math.exp(x)


def sin(x):
    return math.sin(x)


def calculate_distances_and_save(points, filename='distances.h5'):
    points = np.array(points)
    n = len(points)
    distances = []
    for i in range(n):
        for j in range(i + 1, n):
            dx = points[i][0] - points[j][0]
            dy = points[i][1] - points[j][1]
            dist = np.sqrt(dx * dx + dy * dy)
            distances.append(dist)

    with h5py.File(filename, 'w') as f:
        f.create_dataset('distances', data=distances)

    return distances
